<template>
	<view class="content">

		<view class="text-area">
			<text class="title">{{title}}</text>
		</view>

		<image class="logo" :src="`${ !!imgurl?'${imgurl}':'/static/logo.png' }`"></image>
		
		
		<signature border="bottom" style="width: 100%;height:100%;"  :disabled='viewDisabled || appendDisabled'
		   :purpose="'guardian'" :imgurl='formData.guardian' 
		   @signatureHandler="onCompletedHandler"
		></signature>

		<takePhoto style="width: 100%;height:20px" 
		   :purpose="'snapphoto'" :index="index" :disabled="disabled" :imgurl='imgurl'
			@snapHandler="onCompletedHandler">
		</takePhoto>

		<view class='choose-list'>
			<filechoose v-if="project.id" :project="project" @upload="onFileChooseClick"
				@uploadHandler="uploadHandlerParent" :disable="fileChooseEnable" :index="index">
			</filechoose>
		</view>
		<!-- <view>
		  <filelist
		    v-if="formData.ObjectAttachmentIds"
		    :file-ids="formData.ObjectAttachmentids"
		    :disable="!disabled"
		    @removefileids="fileChooseRemove"
		  />
		</view> -->
	</view>
</template>

<script>
	
    import { listSimpleUsersByDeptId } from '../api/system/user.js'
    import { listSimpleDepts } from '../api/system/dept.js'
	//import {filelist} from '../components/common/fileList/index.vue'
   
	export default {
		components: {
			
			//filechoose
			//,filelist
		
		},
		data() {
			return {
				title: '通用组件测试',

				// 签字数据
				custodyUserautograph: '',
				imgurl: '',
				index: 1,
				disabled: true,


				fileChooseEnable: true,
				project: {
					id: 1
				},

				formData: {
					projectId: "",
					ObjectAttachmentIds: ""
				}

			}

		},
		beforeCreate() {
            listSimpleDepts().then(data => {
                console.log(data);
            });
            listSimpleUsersByDeptId(8448).then(data => {
                console.log(data);
            });
		},
		onLoad: function(options) {
			
			console.log(options, '>>>>>>>>options')
		},
		methods: {
			// 文件回传对象attachment 格式
			// {
			// 	"originalName":"VFjJbwjP3Zr81ec86e2c850c45f3155b4d3ca63828e0.jpg",
			// 	"fileName":"2022/04/20/15c918afe28e400b874156f12689b238.jpg",
			// 	"id":"430",
			// 	"url":"http://192.168.31.201:9000/safe-production/2022/04/20/15c918afe28e400b874156f12689b238.jpg",
			// }

			onCompletedHandler(attach) {
                debugger
				// 签字完成
                if (typeof (attach) == 'undefined' || typeof (attach.imgurl) == 'undefined' || typeof (attach.purpose) == 'undefined') {
					return ;
				}
			
				switch(node.purpose){
					case "receiver1":
                        this.$set(this.formData.personList[node.index], "signature", attach.imgurl);
					break;
					case "guardian":
                        this.$set(this.formData, "guardian", attach.imgurl);
						break;
					case "snapphoto":
                        //this.$set(this, "imgurl", attach.imgurl);
                        this.imgurl = attach.imgurl;
						break;
				}
			},

			uploadHandlerParent(attachment, index) {
				this.$set(object, paramName, value);
				// 1.数据关联
				// if (this.samplingData[index].attachmentids) {
				// 	 // 1.2修改			    
				//      this.samplingData[index].attachmentids = `${this.samplingData[index].attachmentids},${fileId}`;
				// } else {
				// 	// 1.1首次操作
				// 	this.samplingData[index].attachmentids = fileId;
				// }

				// 2. ui  
				// 3. 其他操作

			},

			onFileChooseClick() {
				uni.$once("uploadComplate", (fileId) => {
					this.fileChooseUploadHandler(fileId);
				});
				// 上传页面传递参数
				// 上传文件时获取地址参数
				this.$router.navigateTo({
					url: "/engineer/workTicket/components/fileUploadWebView/index",
					params: {
						ids: this.formData.ObjectAttachmentIds,
						fileType: this.listQuery.Q_categoryId_S_EQ,
						projectId: this.project.id,
					},
				});
			},
			// 赋值添加项
			fileChooseUploadHandler(fileId) {
				if (this.formData.ObjectAttachmentIds) {
					this.formData.ObjectAttachmentids = `${this.formData.ObjectAttachmentIds},${fileId}`;
				} else {
					this.formData.ObjectAttachmentIds = fileId;
				}
				this.showFiles2 = false;
				this.$nextTick(() => {
					this.showFiles2 = true;
				});
			},
			fileChooseRemove(index, file) {
				var arr = this.formData.ObjectAttachmentIds.split(",");
				arr.forEach((item, index) => {
					if (item == file) {
						arr.splice(index, 1);
					}
				});
				this.formData.ObjectAttachmentIds = arr.join(",");
			},

			async goWeb() {

				uni.showModal({
					title: "提示",
					content: `请确认下载文件操作?`,
					confirmText: "确定",
					cancelText: "取消",
					showCancel: true,
					success: async (res) => {
						if (res.confirm) {
							await PdfOnline(
								this.formData.title,
								this.listQuery.Q_categoryId_S_EQ,
								this.formData.id
							);
							return;
						}
					},
				});
			}

		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
